/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pe.edu.unmsm.cinfo.siga.datos;

import java.io.Serializable;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author alumno
 */
@Entity
@Table(name = "PERSONAL_UNIDAD")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "PersonalUnidad.findAll", query = "SELECT p FROM PersonalUnidad p"),
    @NamedQuery(name = "PersonalUnidad.findByUniCod", query = "SELECT p FROM PersonalUnidad p WHERE p.personalUnidadPK.uniCod = :uniCod"),
    @NamedQuery(name = "PersonalUnidad.findByPerCod", query = "SELECT p FROM PersonalUnidad p WHERE p.personalUnidadPK.perCod = :perCod"),
    @NamedQuery(name = "PersonalUnidad.findByPerUniCod", query = "SELECT p FROM PersonalUnidad p WHERE p.personalUnidadPK.perUniCod = :perUniCod"),
    @NamedQuery(name = "PersonalUnidad.findByPerUniEst", query = "SELECT p FROM PersonalUnidad p WHERE p.perUniEst = :perUniEst")})
public class PersonalUnidad implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected PersonalUnidadPK personalUnidadPK;
    @Column(name = "PER_UNI_EST")
    private Short perUniEst;
    @JoinColumn(name = "UNI_COD", referencedColumnName = "UNI_COD", insertable = false, updatable = false)
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private Unidad unidad;
    @JoinColumn(name = "PER_COD", referencedColumnName = "PER_COD", insertable = false, updatable = false)
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private Personal personal;
    @JoinColumn(name = "CAR_COD", referencedColumnName = "CAR_COD")
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private Cargo carCod;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "personalUnidad", fetch = FetchType.LAZY)
    private List<Asistencia> asistenciaList;

    public PersonalUnidad() {
    }

    public PersonalUnidad(PersonalUnidadPK personalUnidadPK) {
        this.personalUnidadPK = personalUnidadPK;
    }

    public PersonalUnidad(short uniCod, int perCod, int perUniCod) {
        this.personalUnidadPK = new PersonalUnidadPK(uniCod, perCod, perUniCod);
    }

    public PersonalUnidadPK getPersonalUnidadPK() {
        return personalUnidadPK;
    }

    public void setPersonalUnidadPK(PersonalUnidadPK personalUnidadPK) {
        this.personalUnidadPK = personalUnidadPK;
    }

    public Short getPerUniEst() {
        return perUniEst;
    }

    public void setPerUniEst(Short perUniEst) {
        this.perUniEst = perUniEst;
    }

    public Unidad getUnidad() {
        return unidad;
    }

    public void setUnidad(Unidad unidad) {
        this.unidad = unidad;
    }

    public Personal getPersonal() {
        return personal;
    }

    public void setPersonal(Personal personal) {
        this.personal = personal;
    }

    public Cargo getCarCod() {
        return carCod;
    }

    public void setCarCod(Cargo carCod) {
        this.carCod = carCod;
    }

    @XmlTransient
    public List<Asistencia> getAsistenciaList() {
        return asistenciaList;
    }

    public void setAsistenciaList(List<Asistencia> asistenciaList) {
        this.asistenciaList = asistenciaList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (personalUnidadPK != null ? personalUnidadPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof PersonalUnidad)) {
            return false;
        }
        PersonalUnidad other = (PersonalUnidad) object;
        if ((this.personalUnidadPK == null && other.personalUnidadPK != null) || (this.personalUnidadPK != null && !this.personalUnidadPK.equals(other.personalUnidadPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "pe.edu.unmsm.cinfo.siga.datos.PersonalUnidad[ personalUnidadPK=" + personalUnidadPK + " ]";
    }
    
}
